//
//  MRDestinationCollectionViewCell.m
//  Travel_World
//
//  Created by dllo on 15/10/13.
//  Copyright © 2015年 TLS. All rights reserved.
//

#import "MRDestinationCollectionViewCell.h"

//@property (nonatomic, strong) UIImageView *countryImageView;
//
//@property (nonatomic, strong) UIView *cityCountView;
//
//@property (nonatomic, strong) UILabel *countLabel;
//
//@property (nonatomic, strong) UILabel *cityLabel;
//
//@property (nonatomic, strong) UILabel *cnCountryLabel;
//
//@property (nonatomic, strong) UILabel *enCountryLabel;

@implementation MRDestinationCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.countryImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.countryImageView];
        
        self.cityCountView = [[UIView alloc] init];
        self.cityCountView.backgroundColor = [UIColor blackColor];
        self.cityCountView.alpha = 0.5;
        [self.countryImageView addSubview:self.cityCountView];
        
        self.countLabel = [[UILabel alloc] init];
        self.countLabel.font = [UIFont systemFontOfSize:23];
        self.countLabel.textColor = [UIColor whiteColor];
        self.countLabel.textAlignment = NSTextAlignmentRight;
        [self.cityCountView addSubview:self.countLabel];
        
        self.cityLabel = [[UILabel alloc] init];
        self.cityLabel.font = [UIFont systemFontOfSize:15];
        self.cityLabel.textColor = [UIColor whiteColor];
        self.cityLabel.textAlignment = NSTextAlignmentRight;
        [self.cityCountView addSubview:self.cityLabel];
        
        self.enCountryLabel = [[UILabel alloc] init];
//        self.enCountryLabel.text = @"China";
        self.enCountryLabel.font = [UIFont systemFontOfSize:15];
        self.enCountryLabel.textColor = [UIColor whiteColor];
        [self.countryImageView addSubview:self.enCountryLabel];
        
        self.cnCountryLabel = [[UILabel alloc] init];
        self.cnCountryLabel.font = [UIFont systemFontOfSize:17];
        self.cnCountryLabel.textColor = [UIColor whiteColor];
        [self.countryImageView addSubview:self.cnCountryLabel];
    }
    
    return self;
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.countryImageView.frame = CGRectMake(0, 0, 170 * WID, 250 * HEI);

    if (self.countLabel.text.length > 2) {
        
        NSDictionary *fontDic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:23],NSFontAttributeName, nil];
        CGRect rect = [self.countLabel.text boundingRectWithSize:CGSizeMake(170, 30) options:NSStringDrawingUsesLineFragmentOrigin attributes:fontDic context:nil];
        
        self.cityCountView.frame = CGRectMake(WID * (170 - 35) - rect.size.width, 15 * HEI , rect.size.width + 20 * WID, 60 * HEI);
        
        self.countLabel.frame = CGRectMake(0, 0, rect.size.width + 10, 35 * HEI);
        
        self.cityLabel.frame = CGRectMake(0, 35 * HEI, rect.size.width + 10, 20 * HEI);
        
        
    } else  if (self.countLabel.text.length <= 2) {
        
        NSDictionary *fontDic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:15],NSFontAttributeName, nil];
        
        CGRect rect = [self.cityLabel.text boundingRectWithSize:CGSizeMake(170, 30) options:NSStringDrawingUsesLineFragmentOrigin attributes:fontDic context:nil];
        
        self.cityCountView.frame = CGRectMake(WID * (170 - 35) - rect.size.width, 15 * HEI , rect.size.width + 20 * WID, 60 * HEI);
        
        self.countLabel.frame = CGRectMake(0, 0, rect.size.width + 10, 35 * HEI);
        
        self.cityLabel.frame = CGRectMake(0, 35 * HEI, rect.size.width + 10, 20 * HEI);
        
    }
    
    self.cnCountryLabel.frame = CGRectMake(15 * WID, 180 * HEI, 150 * WID, 30 * HEI);
    
    self.enCountryLabel.frame = CGRectMake(15 * WID, 215 * HEI, 150 * WID, 20 * HEI);
    
    
}


@end
